// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2010-5-13 14:13:53
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   UsersRolesDaoImpl.java

package com.stnet.dao.enterprice.system;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import com.stnet.bases.BaseDaoImpl;
import com.stnet.entity.UsersRoles;

// Referenced classes of package org.stnet.dao.enterprice.system:
//            UsersRolesDao

public class UsersRolesDaoImpl extends BaseDaoImpl implements UsersRolesDao {

	public UsersRolesDaoImpl() {
	}

	public void delete(UsersRoles usersRoles) {
		getHibernateTemplate().delete(usersRoles);
	}

	public void delete(Long id) {
		getHibernateTemplate().delete(get(id));
	}

	public List findAll() {
		List find = getHibernateTemplate().find("from UsersRoles");
		return find;
	}

	public UsersRoles get(Long id) {
		return (UsersRoles) getHibernateTemplate().load(UsersRoles.class, id);
	}

	public void save(UsersRoles usersRoles) {
		getHibernateTemplate().save(usersRoles);
	}

	public void update(UsersRoles usersRoles) {
		getSessionFactory().getCurrentSession().clear();
		getHibernateTemplate().saveOrUpdate(usersRoles);
	}

	public List findByUsersId(Long id) {
		return getHibernateTemplate().find(
				"from UsersRoles where users.id = ?", id);
	}

	public void deleteUsersRoleByUserId(Long userId) {
		Session session = getHibernateTemplate().getSessionFactory()
				.openSession();
		Transaction tx = session.beginTransaction();
		StringBuffer sql = new StringBuffer();
		sql.append("delete UsersRoles where users.id=" + userId);
		Query query = session.createQuery(sql.toString());
		// int dels =
		query.executeUpdate();
		tx.commit();
		session.close();
	}

	public List findByRolesId(Long id) {
		return getHibernateTemplate().find(
				"from UsersRoles where roles.id = ?", id);
	}

	public boolean isGoldByUserIdandRoleId(Long userId, Long roleId) {
		boolean event = false;
		List list = getHibernateTemplate().find(
				"from UsersRoles where roles.id = " + roleId
						+ " and users.id= ?", userId);

		if (list != null && list.size() > 0)
			event = true;
		return event;
	}
}